$package('Bdth.DeviceBind');
Bdth.DeviceBind = function () {
	var _box = null;
	var _this = {
		config: {
			dataGrid: {
				title: '北斗设备列表',
				url: 'dataList',
				pageSize: 200,
				pageList: [200, 500, 1000],
				//queryParams: { "username": username },
				columns: [[
					{field: 'id', checkbox: true, title: 'id'},
					{field: 'bindId', hidden: true},
					{field: 'equipName', title: '显示名称', width: 120, sortable: false},
					{field: 'simNo', title: '设备号', width: 70, sortable: false},
					{field: 'communicationModel', title: '通信模式', width: 100, sortable: false},
					{field: 'depName', title: '所属组', width: 140, sortable: false},
					{field: 'parentSim', title: '指挥卡号', width: 70, sortable: false},
					{
						field: 'isBind',
						title: '绑定状态',
						width: 60,
						sortable: false,
						formatter: function (value, rowData, rowIndex) {
							if (typeof (rowData.parentSim) != 'undefined') {
								if ("" != rowData.parentSim)
									return "已绑定";
								else
									return '<span style="color:red;">未绑定</span>';
							}
							else
								return '<span style="color:red;">未绑定</span>';
						}
					},
				]],
				toolbar: [
					{id: 'btnadd', text: '添加', btnType: 'add'},
					{id: 'btnedit', text: '修改', btnType: 'edit'},
					{id: 'btndelete', text: '删除', btnType: 'remove'}
				]
			}, action: {
				add_editForm: '/view/deviceBind/form.html',
				remove: 'fakeDelete'
			},
			wid_height: {
				width: 600,
				height: 330
			},
		},
		init: function () {
			_box = new DataGrid(_this.config);
			_box.init();
		}
	}
	return _this;
}();

$(function () {
	Bdth.DeviceBind.init();
});
// Grid 工具类
var Utils = {
	getCheckedRows: function () {
		return $('#data-list').datagrid('getChecked');
	},
	checkSelect: function (rows) {// 检查grid是否有勾选的行, 有返回 true,没有返回true
		var records = rows;
		if (records && records.length > 0) {
			return true;
		}
		Bdth.alert('警告', '未选中记录.', 'messager-warning');
		return false;

	},
	checkSelectOne: function (rows) {// 检查grid是否只勾选了一行,是返回 true,否返回true
		var records = rows;
		if (!Utils.checkSelect(records)) {
			return false;
		}
		if (records.length == 1) {
			return true;
		}
		Bdth.alert('警告', '只能选择一行记录.', 'messager-error');
		return false;
	}
}